<template>
  <div class="liebiao">
    <div class="top">
      <router-link to="" @click.native="fanHui()">&lt;</router-link>
      <div class="top_title">订单列表</div>
    </div>
    <div class="lie_biao">
      <ul>
        <li @click="quan" :class="{red:flag==0}">全部</li>
        <li @click="wei" :class="{red:flag==1}">未付款</li>
        <li @click="deng" :class="{red:flag==2}">等待中</li>
        <li @click="yifu" :class="{red:flag==3}">已付款</li>
        <li @click="yifa" :class="{red:flag==4}">已发货</li>
        <li @click="yiqu" :class="{red:flag==5}">已取货</li>
        <li @click="yitui" :class="{red:flag==6}">已退款</li>
      </ul>
    </div>
    <div class="shoping" v-for="(item,index) in arr" :key="index">
      <router-link to="">
        <div class="img">
          <img :src="item.img" alt="" />
        </div>
        <div class="xinxi">
          <p>{{item.title}}</p>
          <div>
            <span>¥{{item.price}}</span>
            <span>x {{item.num}}</span>
          </div>
        </div>
      </router-link>
      <div class="xiang" v-if="item.flag">
        <span>查看订单</span>
        <span @click="tanchu(item.chang)">删除订单</span>
      </div>
      <div class="tan_chu" v-show="flag2">
      <span>亲，你确定删除该订单？</span>
      <div>
        <span @click="queDin()">确定</span>
        <span @click="qunXiao()">取消</span>
      </div>
    </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag:0,
      arr:[],
      flag2:false,
      chang:0
    };
  },
  methods: {
    fanHui() {
      window.history.go(-1);
    },
    tanchu(chang){
      this.flag2=true
      this.chang=chang
    },
    // 取消
    qunXiao(){
      this.flag2 = false
    },
    // 确定删除
    queDin(){
     this.$axios.get('http://47.114.130.21:3000/dindan',{
        params:{
          id:localStorage.getItem("id"),
          shibie:30,
          chang:this.chang
        }
      }).then((data)=>{
        this.arr=data.data.msg;
        this.flag2 = false;
      })
    },
    quan(){
      this.flag=0
      this.$axios.get('http://47.114.130.21:3000/dindan',{
        params:{
          id:localStorage.getItem("id"),
          shibie:this.flag,
        }
      }).then((data)=>{
        if(data.data.code==200){
          this.arr=data.data.msg;
        }
      })
    },
    wei(){
      this.flag=1
      this.$axios.get('http://47.114.130.21:3000/dindan',{
        params:{
          id:localStorage.getItem("id"),
          shibie:this.flag,
        }
      }).then((data)=>{
        if(data.data.code==200){
          this.arr=data.data.msg;
        }
      })
    },
    deng(){
      this.flag=2
    },
    yifu(){
      this.flag=3
      this.$axios.get('http://47.114.130.21:3000/dindan',{
        params:{
          id:localStorage.getItem("id"),
          shibie:this.flag
        }
      }).then((data)=>{
        if(data.data.code==200){
          this.arr=data.data.msg;
        }
      })
    },
    yifa(){
      this.flag=4
    },
    yiqu(){
      this.flag=5
    },
    yitui(){
      this.flag=6
    },
  },
  mounted(){
      this.$axios.get('http://47.114.130.21:3000/dindan',{
        params:{
          id:localStorage.getItem("id"),
          shibie1:0,
          shibie:20,
          arr:this.$store.state.arr,
        }
      }).then((data)=>{
        if(data.data.code==200){
          this.arr=data.data.msg;
        }
      })
  }
};
</script>

<style lang="less" scoped>
.liebiao {
  .lie_biao {
    margin-top: 45px;
    width: 100%;
    > ul {
      white-space: nowrap;
      overflow-x: auto;
      width: 100%;
      height: 1.066667rem;
      background: #ffffff;
      display: flex;
      flex-flow: row nowrap;
      border-bottom: 1px solid #ccc;
      >.red{
        color:#de0a2b;
      }
      > li {
        flex-shrink: 0;
        width: 23%;
        font-size: 14px;
        color: #353535;
        height: 100%;
        line-height: 1.066667rem;
        text-align: center;
      }
    }
  }
  .shoping {
    background: #ffffff;
    width: 100%;
    display: flex;
    flex-flow: column;
    border-bottom: 1px solid #eee;
    .tan_chu {
    height: 2.133333rem;
    width: 5.866667rem;
    background: rgba(204, 204, 204, 0.5) !important;
    position: fixed;
    left: 50%;
    top: 35%;
    transform: translateX(-50%);
    border-radius: 5px;
    display: flex;
    flex-flow: column;
    justify-content: space-around;
    align-items: center;
    > span {
      font-size: 15px;
    }
    > div {
      width: 100%;
      display: flex;
      flex-flow: row;
      justify-content: space-around;
      align-items: center;
      > :first-child {
        color: #ffffff;
        background: #de0a2b;
        padding: 0.213333rem 0.4rem;
        border-radius: 3px;
      }
      > :last-child {
        padding: 0.213333rem 0.4rem;
        border-radius: 3px;
        color: #000;
        background: #ffffff;
      }
    }
  }
    >a{
      display: flex;
      flex-flow: row;
      justify-content: space-between;
      width: 100%;
      padding: 0.133333rem 0.266667rem;
      >.img{
        width: 20%;
        >img{
          width: 100%;
        }
      }
      >.xinxi{
        width: 75%;
        display: flex;
        flex-flow: column;
        justify-content: space-around;
        >p{
          font-size: 12px;
          color: #353535;
          line-height: 17px;
        }
        >div{
          display: flex;
          flex-flow: row;
          justify-content: space-between;
          >:first-child{
            font-size: 14px;
            color:#de0a2b;
          }
          >:last-child{
            font-size: 14px;
            color:#353535;
          }
        }
      }
    }
    >.xiang{
      display: flex;
      flex-flow: row;
      justify-content: space-around;
      margin-bottom: 0.233333rem;
      >span{
        border-radius: 25px;
        padding: 0.133333rem 0.4rem;
        color: #353535;
        border: 1px solid #ccc;
      }
    }
  }
}
</style>